package codingStudy.netEase2018Spring;

import java.util.Scanner;

/**
 * @author zcxv
 * @category 赶去公司
 */
public class GoToWork {

	static int slove(int N, int[] tx, int[] ty, int gx, int gy, int walkTime,
			int taxiTime) {
		// 遍历每种情况需要花费的时间
		int distance = Math.abs(gx)+Math.abs(gy);
		int time = walkTime*distance;
		
		int result = 0;
		int[] walkDistance = countWalkDistance(tx, ty);
		int[] taxiDistance = countTaxiDistance(tx, ty, gx, gy);
		for (int i = 0; i < N; i++) {
			result = walkTime * walkDistance[i] + taxiTime * taxiDistance[i];
			if (result < time) {
				time = result;
			}
		}
		return time;
	}

	// 计算步行到出租车的距离
	static int[] countWalkDistance(int[] tx, int[] ty) {
		int[] distance = new int[tx.length];
		for (int i = 0; i < tx.length; i++) {
			distance[i] = Math.abs(tx[i]) + Math.abs(ty[i]);
		}
		return distance;

	}

	// 计算出租车到终点的距离
	static int[] countTaxiDistance(int[] tx, int[] ty, int gx, int gy) {
		int[] distance = new int[tx.length];
		for (int i = 0; i < tx.length; i++) {
			distance[i] = Math.abs(gx - tx[i]) + Math.abs(gy - ty[i]);
		}
		return distance;

	}

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入周围出租车打车点个数n：");
		int n = scanner.nextInt();
		int tx[] = new int[n];
		System.out.println("请输入每个出租车打车点点横坐标（以空格隔开）：");
		for (int i = 0; i < n; i++) {
			tx[i] = scanner.nextInt();
		}
		System.out.println("请输入每个出租车打车点点纵坐标（以空格隔开）：");
		int ty[] = new int[n];
		for (int i = 0; i < n; i++) {
			ty[i] = scanner.nextInt();
		}
		System.out.println("请输入办公室坐标（以空格隔开）：");
		int gx = scanner.nextInt();
		int gy = scanner.nextInt();
		System.out.println("请输入行走和打出租车的速度（以空格隔开）：");
		int walkTime = scanner.nextInt();
		int taxiTime = scanner.nextInt();

		System.out.println(slove(n, tx,ty,gx,gy,walkTime,taxiTime));
		scanner.close();
	}
}